#include "led_task.h"

void Led_task(void const * argument)
{
    uint8_t c_flag=0;
	uint8_t i_flag=0;
    //HAL_GPIO_WritePin(KEY_GPIO_Port,KEY_Pin,GPIO_PIN_SET);
    while(1){
        switch(led_c){
            case 0:
                LED_R_H();
                LED_G_L();
                LED_B_L();
			    if(nuc_connect_flag==1){
						if(i_flag==0){
							rc_ctrl.rc.s[1]=1;
							i_flag=1;
						}
						
					c_flag=2;
				}
				break;
            case 1:
                LED_R_L();
                LED_G_H();
                LED_B_L();
                c_flag=1;
                break;
            case 2:
                LED_R_L();
                LED_G_L();
                LED_B_H();
                break;
        }
//        if(HAL_GPIO_ReadPin(KEY_GPIO_Port,KEY_Pin)==GPIO_PIN_RESET){
//            osDelay(15);
//            if(HAL_GPIO_ReadPin(KEY_GPIO_Port,KEY_Pin)==GPIO_PIN_RESET){
//                key_flag=!key_flag;
//            }
//				}		
        if(dect_finish==1){
            led_st();
        }
        dect_finish=0;    
        Send_vofa(2);
        //led_c=led_c%3;
        //send_flag=1;nuc_connect_flag==1 && 
        if(data_get_from_nuc_flag==1){
            led_c=1;
            //data_get_from_nuc_flag=0;
        }
        if(c_flag==1 || c_flag==2){
            c_flag=0;
            led_c=2;
            osDelay(100);
        }
				// if(timescount_flag==1){
				// 	send_timescount++;
				// }
				if(go_to_disk_flag==1){
					timescount_disk++;
				}
        osDelay(100);
    }
}

void cmd_running_if(void)
{
    if(data_get_from_nuc[2]==0x72){
        if(data_get_from_nuc[4]==0x00){
            if(nuc_run_if!=1){
                dect_finish=1;
            }
        }
        else if(data_get_from_nuc[4]==0x03){
            if(nuc_run_if!=2){
                dect_finish=1;
            }
        }
    }
    if(data_get_from_nuc[2]==0x74){
        if(data_get_from_nuc[4]==0x01){
            if(nuc_run_if!=3){
                dect_finish=1;
            }
        }
        if(data_get_from_nuc[4]==0x02){
            if(nuc_run_if!=4){
                dect_finish=1;
            }
        }
    }
		if(data_get_from_nuc[2]==0x74){
				if(data_get_from_nuc[4]==0x01){
            if(nuc_run_if!=5){
                dect_finish=1;
            }
        }
		}
}

void led_st(void)
{
    if(data_get_from_nuc[2]==0){
        led_c=0;
    }
    else if(data_get_from_nuc[2]==1){
        led_c=1;
    }
    else if(data_get_from_nuc[2]==2){
        led_c=2;
    }
}
